package com.liuchuanzheng.lcz_viewmove

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.view.ViewGroup
import android.widget.Toast
import com.google.android.material.internal.ViewUtils
import com.liuchuanzheng.lcz_viewmove.databinding.ActivityLayoutParamsBinding

@SuppressLint("RestrictedApi")
class ScrollByActivity : AppCompatActivity() {
    lateinit var mViewBinding: ActivityLayoutParamsBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mViewBinding = ActivityLayoutParamsBinding.inflate(layoutInflater)
        setContentView(mViewBinding.root)
        //直接取宽高会不准.必须等待测量完
        mViewBinding.tvMove.post {
            mViewBinding.tvMove.apply {
                var str = "x:${x}\n    =\nleft:${left}\n    +\nTranslationX:${translationX}\n\nscrollx:${scrollX}"
                mViewBinding.tvBefore.text = str
            }
        }

        mViewBinding.tvMove.setOnClickListener {
            Toast.makeText(this, "点击", Toast.LENGTH_SHORT).show()
        }
        mViewBinding.btnStart.setOnClickListener {
            /**
             * getLeft() 不变
             * getX() 不变
             * getTranslationX() 不变
             * getScrollX() 变
             * 点击区域 不变
             * 是否影响其他view的位置 否
             */
            //这与scrollto的区别应该都懂.不用再演示了
            //方向是反的,实际会向右滚动
            mViewBinding.tvMove.scrollBy(ViewUtils.dpToPx(this, -10).toInt(),0)
            mViewBinding.tvMove.post {
                mViewBinding.tvMove.apply {
                    var str = "x:${x}\n    =\nleft:${left}\n    +\nTranslationX:${translationX}\n\nscrollx:${scrollX}\n点击区域:不变\n是否影响其他view的位置:否"
                    mViewBinding.tvAfter.text = str
                }
            }

        }
    }
}